/*
 * @Author: your name
 * @Date: 2021-03-23 15:08:39
 * @LastEditTime: 2021-04-09 19:44:53
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \shop\training-group-5-warehouse\dianshang\src\router\index.js
 */
import Vue from "vue";
import VueRouter from "vue-router";
import Seckill from "../views/seckill";
import Info from "../views/info";
import Zhifu from "../views/pay/zhifu.vue";
import Topayment from "../views/pay/topayment.vue";
import Paycg from "../views/pay/paycg.vue";
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/login",
  },
  //余额
  {
    path: "/balance",
    name: "Balance",
    component: () => import("../views/balance"),
  },
  //消费记录
  {
    path: "/consumption",
    name: "Consumption",
    component: () => import("../views/consumption"),
  },
  //银行卡
  {
    path: "/bankCard",
    name: "BankCard",
    component: () => import("../views/bankCard"),
  },
  //银行卡绑定
  {
    path: "/bankCardBinding",
    name: "BankCardBinding",
    component: () => import("../views/bankCardBinding"),
  },
  {
    path: "/bankCardBindings",
    name: "BankCardBindings",
    component: () => import("../views/bankCardBinding/two.vue"),
  },
  //验证码
  {
    path: "/verificationCode",
    name: "VerificationCode",
    component: () => import("../views/verificationCode"),
  },
  {
    path: "/verificationCodes",
    name: "VerificationCodes",
    component: () => import("../views/verificationCode/two.vue"),
  },
  //添加银行卡
  {
    path: "/addBack",
    name: "AddBack",
    component: () => import("../views/addBack"),
  },
  //银行卡s
  {
    path: "/bankCards",
    name: "BankCards",
    component: () => import("../views/bankCards"),
  },
  //支付1
  {
    path: "/payment",
    name: "Payment",
    component: () => import("../views/pays/payment"),
  },
  //充值成功
  {
    path: "/worm",
    name: "Worm",
    component: () => import("../views/worm"),
  },
  //充值未绑卡
  {
    path: "/recharge",
    name: "Recharge",
    component: () => import("../views/Recharge"),
  },
  //详情页
  {
    path: "/details",
    name: "Details",
    component: () => import("../views/details"),
  },
  {
    path: "/seckill",
    name: "Seckill",
    component: Seckill,
  },
  {
    path: "/info/:id",
    name: "Info",
    component: Info,
  },
  {
    path: "/zhifu",
    name: "Zhifu",
    component: Zhifu,
  },
  {
    path: "/topayment",
    name: "Topayment",
    component: Topayment,
  },
  {
    path: "/paycg",
    name: "Paycg",
    component: Paycg,
  },
  {
    path: "/login",
    component: () => import("@views/Login"),
  },
  {
    path: "/register",
    component: () => import("@views/Register"),
  },
  {
    path: "/layout",
    component: () => import("@/layout"),
    children: [
      {
        path: "/layout/home",
        component: () => import("@/views/Home/index.vue"),
      },
      //分类
      {
        path: "/layout/classify",
        component: () => import("@/views/Classify"),
      },
      //购物车
      {
        path: "/layout/car",
        component: () => import("@/views/Car"),
      },
      //我的
      {
        path: "/layout/my",
        component: () => import("@/views/My"),
      },
    ],
  },
  //砍价
  {
    path: "/bargain",
    component: () => import("@/views/Bargain"),
  },
  //invitation砍价记录
  {
    path: "/invitation",
    component: () => import("@/views/Invitation"),
  },
  //微信weChat
  {
    path: "/weChat",
    component: () => import("@/views/WeChat"),
  },
  //直播特卖
  {
    path: "/live",
    component: () => import("@/views/Live"),
  },
  //直播间
  {
    path: "/direct",
    component: () => import("@/views/Direct"),
  },
  //邀请好友来拼团
  {
    path: "/group",
    component: () => import("@/views/Group"),
  },
  //拼团记录
  {
    path: "/groupstatus",
    component: () => import("@/views/GroupStatus"),
  },
  {
    path: "/set",
    component: () => import("@/views/set"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});
//全局路由守卫
router.beforeEach((to, from, next) => {
  //查找路由标识
  console.log(to);
  if (to.meta.isLogin) {
    if (sessionStorage.getItem("token")) {
      next();
    } else {
      next("/login");
    }
  }
  next();
});
export default router;
